<?php
require_once "backend/model/Dishes.php";

$model = new Dishes;

$day = 1;

$arrStatus = $arrID = $arrEat = $arrDrink = $arrSold = $arrDetail = $arrSoldID = $arrEatID = $arrDrinkID = array();

$rs_eat = mysql_query("SELECT * FROM menu WHERE type = 1 AND day = $day ORDER BY display_order");
while($row_eat = mysql_fetch_assoc($rs_eat)){
	$arrEatID[] = $row_eat['id'];
	$arrStatus[$row_eat['id']] = $row_eat['status'];
	$arrID[$row_eat['id']] = $row_eat['id'];
}
$rs_drink = mysql_query("SELECT * FROM menu WHERE type = 2 AND day = $day  ORDER BY display_order");
while($row_drink = mysql_fetch_assoc($rs_drink)){
	$arrDrinkID[] = $row_drink['id'];
	$arrStatus[$row_drink['id']] = $row_drink['status'];
	$arrID[$row_drink['id']] = $row_drink['id'];
}
if(!empty($arrID)){
	$str_id = implode($arrID,",");

	$sql = "SELECT * FROM dishes WHERE id IN (".$str_id.")";
	$rs = mysql_query($sql) or die(mysql_error());
	while($row_cu = mysql_fetch_assoc($rs)){		
		$arrDetail[$row_cu['id']] = $row_cu;
	}
}

//check xem co menu ngay mai hay chưa
$rs_count =mysql_query("SELECT * FROM menu WHERE day = 2 AND status = 1");
$have_tomorrow = mysql_num_rows($rs_count);	
?>
<div class="section-spacing" id="alfred">
	<div class="row">
		<div class="large-10 large-centered medium-10 medium-centered small-12 columns">
			<h3 class="title">

			<?php echo $is_open==true ? "-Menu Hôm Nay-" : "Sorry, we're closed."; ?></h3>
			<h5 class="soft-title"><?php echo $is_open==true ? "Đặt trước 10h30 để được phục vụ tốt nhất." : "Giờ mở cửa từ thứ 2 đến thứ 6, 11:00am - 02:00pm";  ?></h5>
		</div>
	</div>
</div>
<div id="menu">
	<div class="row">
		
			<input id="utf8" name="utf8" value="✓" type="hidden"><input id="authenticity_token" name="authenticity_token" value="1kr1V4uSVdBc3S91hUKgVi1oKnP6OhLYed+Kecgg99Y=" type="hidden">
			<div class="row meal-row" style="margin:auto">
				<?php if(!empty($arrEatID)){ 
					$i = 0;
					$total = count($arrEatID);
				foreach ($arrEatID as $value) {
					$i++;
					$tmp = $arrDetail[$value];
					?>
				<div class="small-12 medium-6 columns meal <?php echo $i==$total ? "end" : ""; ?>">
					<div class="meal-poster">
						<img  alt="<?php echo $tmp['name']; ?>" src="<?php echo $tmp['image_url']; ?>">
						<div class="action-bar" >
							<h6>
							<?php if($is_open==true) { ?>
							<?php echo $arrStatus[$tmp['id']]==1 ? "<span class='avai'>Availuable!</span>" : "<span class='sold'>Sold out!</a>"; ?>
							<?php } else { ?>
							<span class='avai'>Hẹn gặp lại bạn vào ngày mai</span>
							<?php } ?>
							</h6>
						</div>
					</div>
					<div class="meal-info row">
						<div class="meal-heading small-9 large-8 columns data-equalizer-watch">
							<h6 class="title"><?php echo $tmp['name']; ?>
							<br />
							<span class="name_en"><?php echo $tmp['name_en']; ?></span></h6>
							<p class="tags muted-title">
							</p>
						</div>
						<div class="meal-price small-3 large-4 columns">
							<h5 class="soft-title"><?php echo number_format($tmp['price']); ?><sup>đ</sup></h5>
						</div>
					</div>
					<div class="meal-add-info row">
						<ul class="small-12 medium-12 large-12 columns tabs" data-tab="">
							<li class="tab-title active">
								<a class="icon-text soft-title" href="#meal-<?php echo $tmp['id']; ?>-panel2-1">
									<img alt="Info icon" class="icon-small" src="images/mota.png">
									Mô tả
								</a>
								</li>
							<li class="tab-title">
								<a class="icon-text soft-title" href="#meal-<?php echo $tmp['id']; ?>-panel2-2">
									<img alt="Nutrition icon" class="icon-small" src="images/thanhphan.png">
									Thành phần
								</a>
							</li>
						</ul>
					</div>
					<div class="tabs-content">
						<div style="height: 237px;" class="content active" id="meal-<?php echo $tmp['id']; ?>-panel2-1">
							<p class="soft-text">
								<?php echo $tmp['description'];?>
							</p>
						</div>
						<div style="height: 237px;" class="content" id="meal-<?php echo $tmp['id']; ?>-panel2-2">
							<p class="soft-text">
								<?php echo $tmp['components'];?>
							</p>
						</div>
					</div>
				</div>
				<?php } } ?>
				
			</div>


			<div class="row meal-row" style="margin:auto">
				<?php if(!empty($arrDrinkID)){ 
					$i = 0;
					$total = count($arrDrinkID);
					foreach ($arrDrinkID as $value) {
						$i++;
						$tmp = $arrDetail[$value];
						?>
				<div class="small-12 medium-6 large-4 columns meal <?php echo $i==$total ? "end" : ""; ?>">
					<div class="meal-poster">
						<img alt="<?php echo $tmp['name']; ?>" src="<?php echo $tmp['image_url']; ?>">
						<div class="action-bar">								
							<h6>
							<?php if($is_open==true) { ?>
							<?php echo $arrStatus[$tmp['id']]==1 ? "<span class='avai'>Availuable!</span>" : "<span class='sold'>Sold out!</a>"; ?>
							<?php } else { ?>
							<span class='avai'>Hẹn gặp lại bạn vào ngày mai</span>
							<?php } ?>
							</h6>
						</div>
					</div>
					<div class="meal-info row">
						<div class="meal-heading small-9 large-8 columns data-equalizer-watch">
							<h6 class="title"><?php echo $tmp['name']; ?><br />
							<span class="name_en"><?php echo $tmp['name_en']; ?></span></h6>
							<p class="tags muted-title">
							</p>
						</div>
						<div class="meal-price small-3 large-4 columns">
							<h5 class="soft-title"><?php echo number_format($tmp['price']); ?><sup>đ</sup></h5>
						</div>
					</div>
					<div class="meal-add-info row">
						<ul class="small-12 medium-12 large-12 columns tabs" data-tab="">
							<li class="tab-title active">
								<a class="icon-text soft-title" href="#meal-<?php echo $tmp['id']; ?>-panel2-1"><img alt="Info icon" class="icon-small" src="images/mota.png">Mô tả</a></li>
							<li class="tab-title">
								<a class="icon-text soft-title" href="#meal-<?php echo $tmp['id']; ?>-panel2-2"><img alt="Nutrition icon" class="icon-small" src="images/thanhphan.png">Thành phần</a></li>
						</ul>
					</div>
					<div class="tabs-content">
						<div style="height: 216px;" class="content active" id="meal-<?php echo $tmp['id']; ?>-panel2-1">
							<p class="soft-text">
								<?php echo $tmp['description'];?>
							</p>
						</div>
						<div style="height: 216px;" class="content" id="meal-<?php echo $tmp['id']; ?>-panel2-2">
							<p class="soft-text">
								<?php echo $tmp['components'];?>
							</p>
						</div>
					</div>
				</div>
				<?php } } ?>			
				
			</div>
		
	</div>
</div>
<div class="small-section-spacing" id="checkout-section">
	<div class="row">
		<div class="small-12 small-centered columns">
			<div class="has-form cart powercenter">
				<a class="hotl" href="javascript:void(0)">
					<img src="images/phone.png" style="height:20px">
					0938 938 938
				</a>
			</div>
		</div>
	</div>
</div>	
<script src="static/home.js"></script>
<div class="section-spacing" id="alfred">
	<div class="row">
		<div class="large-10 large-centered medium-10 medium-centered small-12 columns">
			<h3 class="title">-Menu Ngày Mai-</h3>
			<h5 class="soft-title">Đặt trước một ngày để được giảm giá 5%.</h5>
		</div>
	</div>
</div>

<div class="powercenter section-spacing" id="media">
	<div class="row">
		<img alt="logo" src="images/logoa.png" style="width:110px" />
	</div>
	
</div>